package com.blog.wl2023.repository;

import com.blog.wl2023.entity.MessageList;
import com.blog.wl2023.entity.TreasureChests;
import jakarta.persistence.Column;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * @author wule
 * @desc
 */
@Repository
public interface MessageListRepository extends JpaRepository<MessageList, Long>, JpaSpecificationExecutor<MessageList> {

	@Query(value = "select m from MessageList m LEFT JOIN FETCH m.user where m.isDelete=0 order by m.createTime desc")
	List<MessageList> getMessageList();

	@Modifying
	@Transactional
	@Query("update MessageList a set a.isDelete=:isDelete where a.uuid = :uuid")
	void updateMessageListIsDelete(String uuid, Integer isDelete);
}
